import { customRef } from 'vue'
function useDebounceRefs(value) {
  return customRef((track, trigger) => ({
    get() {
      // 收集依赖
      track()
      return value
    },
    set(newValue) {
      value = newValue
      // 触发更新
      trigger()
      return true
    },
  }))
}
function useDebounceRefsDelay(value) {
  let timer = null
  return customRef((track, trigger) => ({
    get() {
      // 收集依赖
      track()
      return value
    },
    set(newValue) {
      timer && clearTimeout(timer)
      timer = setTimeout(() => {
        value = newValue
        // 触发更新
        trigger()
      }, 1000)
      return true
    },
  }))
}
export { useDebounceRefs, useDebounceRefsDelay }
